﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Ewts.Storage
{
    public partial class TallyList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request["loadid"] != null && Request["loadid"].ToString().Trim() != "" && Request["loadid"].ToString().Trim() != "0")
                {
                    bindData(int.Parse(Request["loadid"].ToString().Trim()), 0);
                }
                else if (Request["outid"] != null && Request["outid"].ToString().Trim() != "" && Request["outid"].ToString().Trim() != "0")
                {
                    bindData(0, int.Parse(Request["outid"].ToString().Trim()));
                }
            }
        }

        protected void bindData(int loadid,int outid)
        {
            DataTable dt = new DataLib.BLL.Tally().GetTallyList(loadid, outid);
            reptTallyList.DataSource = dt;
            reptTallyList.DataBind();

        }

        protected void reptTallyList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            int id = 0;
            int loadid = 0;
            int outid = 0;
            if (e.CommandName == "Delete")
            {
                id = int.Parse(e.CommandArgument.ToString());
                DataLib.BLL.Tally blltally = new DataLib.BLL.Tally();
                DataLib.Model.Tally mtally = blltally.GetModel(id);
                new DataLib.BLL.TallyAfter().dellist("tallyid=" + id.ToString());
                new DataLib.BLL.TallyBefore().dellist("tallyid=" + id.ToString());
                DataLib.Model.tab_delNo mNo = new DataLib.Model.tab_delNo();
                mNo.createtime = DateTime.Now;
                mNo.delno = mtally.tallyno;
                mNo.delid = mtally.id;
                loadid = (int) mtally.loadid;
                outid = (int)mtally.outid;
                mNo.isdel = 0;
                mNo.tabname = "tally";
                new DataLib.BLL.tab_delNo().Add(mNo);
            }
            bindData(loadid, outid);
         }
    }
}